#include <iostream>
using namespace std;

int main() {
    int n;
    cin>>n;
    int prices[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>prices[i];
    }
    int minPrice=prices[1];
    int maxProfit=0;
    for(int i=2;i<=n;i++){
        minPrice=min(minPrice,prices[i]);
        maxProfit=max(maxProfit,prices[i]-minPrice);
    }
    cout<<maxProfit<<endl;
    return 0;
}
